var BulletC = Bullet.extend({
    _xSpdScale : 1,
    _ySpdScale : 1,
    ///////////////////////////////////////////////////////////
    ctor : function(filename,power,speed,type){
        this._super(filename,power,speed,type);
        this._target = new Array();
    },
    onEnter:function () {
        this._super();
    },
    onExit : function(){
        var length = this._target.length;
        this._target.splice(0,length); // just clear buffer
        this._super();
    },
    ////////////////////////// settings ////////////////////////
    revive : function(){
        this.setLife(true);
        this.setVisible(true);
    },
    recover : function(){
        this.setLife(false);
        this.setVisible(false);
        this.clearTarget();
    },
    ////////////////////////// angle //////////////////////////
    angle : function( targetPos ) {
        var fenZi =  targetPos.y - this.bornPos.y;
        var fenMu =  targetPos.x - this.bornPos.x;
        var angle = Math.atan( fenZi/fenMu );
        return -angle*180*0.318310;
    },
    // you must set this position first
    setSpeedScale : function(targetPos,distance){
        var xScale = ( targetPos.x - this.getPositionX() )/distance;
        var yScale = ( this.getPositionY() - targetPos.y )/distance;
        this._xSpdScale =  xScale;
        this._ySpdScale =  yScale;
        this.runAction( cc.RepeatForever.create(
            cc.RotateBy.create( 1,-360 )
        ) );
    },
    ////////////////////////// target //////////////////////////
    clearTarget : function(){
        var length = this._target.length;
        this._target.splice(0,length); // just clear buffer
    },
    findTarget : function(target){
        var length = this._target.length;
        for( var i=0;i<length;i++){
            var temp = this._target[i];
            if(null!=temp&&temp==target){
                return true;
            }
        }
        return false;
    },
    pushTargetBack:function(target){
        this._target.push(target);
    },
    ////////////////////////// moving //////////////////////////
    moving : function(dt){
        if ( this.isVisible() ){
            var x = this.x, y = this.y;
            var rota = this.getRotation();
            this.x = x + this._speed * this._xSpdScale * dt;
            this.y = y - this._speed * this._ySpdScale * dt;
            var winSize = cc.director.getWinSize();
            if ( x < 0 || x > winSize.width || y < 0 || y > winSize.height ) {
                this.recover();
                this.stopAllActions();
            }
        }
    },
    collideRect:function (x, y) {
        var width=30,height=30;
        return cc.rect(x-width*0.5, y-height*0.5, width, height);
    }
});
